﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using entity;

namespace DAL
{
    /// <summary>
    ///StockNoticeDAL 的摘要说明
    /// </summary>
    public class StockNoticeDAL
    {
        public List<StockNotice> GetStockNoticeByStockId(string stockId)
        {
            string sql = "select notice_id,stock_id,stock_name,notice_title,notice_date from  vw_stock_notice where stock_id=@stockId order by notice_date desc";
            Tools tool = new Tools();
            tool.AddSqlParameter("stockId", SqlDbType.VarChar, stockId);
            DataTable tb= SqlHelper.ExecuteGetTable(DBManager.qgqp, CommandType.Text, sql, tool.GetSqlParameters());
            List<StockNotice> lst = new List<StockNotice>();
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                DataRow row =tb.Rows[i];
                StockNotice s = new StockNotice();
                s.StockId = Tools.GetString(row["stock_id"]);
                s.NoticeId = Tools.GetLong(row["notice_id"]);
                s.StockName = Tools.GetString(row["stock_name"]);
                s.Title = Tools.GetString(row["notice_title"]);
                s.NoticeDate = Tools.GetDateTime(row["notice_date"]);
                lst.Add(s);
            }
            return lst;
        }

        public List<StockNotice> GetStockNoticeByDate(DateTime date)
        {
            string sql = "select notice_id,stock_id,stock_name,notice_title,notice_date,notice_content from  vw_stock_notice where notice_date=@date order by notice_date desc";
            Tools tool = new Tools();
            tool.AddSqlParameter("date", SqlDbType.DateTime, date);
            DataTable tb = SqlHelper.ExecuteGetTable(DBManager.qgqp, CommandType.Text, sql, tool.GetSqlParameters());
            List<StockNotice> lst = new List<StockNotice>();
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                DataRow row = tb.Rows[i];
                StockNotice s = new StockNotice();
                s.StockId = Tools.GetString(row["stock_id"]);
                s.NoticeId = Tools.GetLong(row["notice_id"]);
                s.StockName = Tools.GetString(row["stock_name"]);
                s.Title = Tools.GetString(row["notice_title"]);
                s.NoticeDate = Tools.GetDateTime(row["notice_date"]);
                lst.Add(s);
            }
            return lst;
        }

        public StockNotice GetNoticeById(long id)
        {
            string sql = "select notice_id,stock_id,stock_name,notice_title,notice_date,notice_content from  vw_stock_notice where notice_id=@id";
            Tools tool = new Tools();
            tool.AddSqlParameter("id", SqlDbType.BigInt, id);
            DataTable tb = SqlHelper.ExecuteGetTable(DBManager.qgqp, CommandType.Text, sql, tool.GetSqlParameters());
            StockNotice c = null;
            if (tb.Rows.Count > 0)
            {
                c = new StockNotice();
                DataRow row = tb.Rows[0];
                c.StockId = Tools.GetString(row["stock_id"]);
                c.NoticeId = Tools.GetLong(row["notice_id"]);
                c.StockName = Tools.GetString(row["stock_name"]);
                c.Title = Tools.GetString(row["notice_title"]);
                c.NoticeDate = Tools.GetDateTime(row["notice_date"]);
                c.Content = Tools.GetString(row["notice_content"]);
            }
            return c;
        }
    }
}